import 'package:flutter/material.dart';
import 'package:flutter01/GetX/middleware/permissionMiddleWare.dart';
import 'package:flutter01/GetX/routes/prod.dart';
import 'package:flutter01/GetX/routes/setting.dart';
import 'package:flutter01/GetX/routes/user.dart';
import 'package:get/get.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      theme: ThemeData(
        useMaterial3: false,
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text("Flutter APP"),
        ),
        body: const MyHome(),
      ),
      //Get设置默认的路由动画
      defaultTransition: Transition.native,
      //GetX使用getPages来配置路由
      getPages: [
        //可以指定中间件,进行一些权限拦截操作
        GetPage(name: "/user", page: () => const UserPage(),middlewares: [PermissionMiddleWare()]),
        //transition可以指定路由动画
        GetPage(name: "/prod", page: () => const ProdPage(),transition: Transition.leftToRight),
        //路由传递参数也无需其他额外配置
        GetPage(name: "/setting", page: () => const SettingPage()),
      ],
    );
  }
}

class MyHome extends StatelessWidget {
  const MyHome({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ElevatedButton(onPressed: (){
            Get.toNamed("/user");
          }, child: const Text("跳转到User页")),
          ElevatedButton(onPressed: (){
            //GetX 跳转路由
            Get.toNamed("/prod");
          }, child: const Text("跳转到Prod页")),
          ElevatedButton(onPressed: (){
            //GetX 跳转传值
            Get.toNamed("/setting",arguments: {
              "aid":123
            });
          }, child: const Text("跳转到Setting页")),
        ],
      ),
    );
  }
}


